package edu.xhu.adapters;

import java.util.ArrayList;

import com.bean.ExamineBean;

import edu.xhu.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class EduSystemExameAdapter extends BaseAdapter{

	private ArrayList<ExamineBean> mExamineList;
	private LayoutInflater inflater;
	
	public EduSystemExameAdapter(Context context, ArrayList<ExamineBean> mExamineList){
		this.mExamineList = mExamineList;
		inflater = LayoutInflater.from(context);
	}
	
	public int getCount() {
		if (null == mExamineList)
			return 0;
		return mExamineList.size();
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (null == convertView){
			viewHolder				= new ViewHolder();
			convertView				= inflater.inflate(R.layout.edusystem_exame_item, null);
			viewHolder.courseName	= (TextView) convertView.findViewById(R.id.textview_coursename);
			viewHolder.courseNumber	= (TextView) convertView.findViewById(R.id.textview_course_number);
			viewHolder.exameTime	= (TextView) convertView.findViewById(R.id.textview_exametime);
			viewHolder.examePlace	= (TextView) convertView.findViewById(R.id.textview_exameplace);
			viewHolder.exameType	= (TextView) convertView.findViewById(R.id.textview_exametype);
			viewHolder.placeNumber	= (TextView) convertView.findViewById(R.id.textview_placenumber);
			viewHolder.schoolPart	= (TextView) convertView.findViewById(R.id.textview_schoolpart);
			
			convertView.setTag(viewHolder);
		}else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		ExamineBean tmpBean = mExamineList.get(position);
		viewHolder.courseName.setText("名字：" + tmpBean.courseName);
		viewHolder.courseNumber.setText("选课课号：" + tmpBean.examineId);
		viewHolder.exameTime.setText("时间：" + getString(tmpBean.time));
		viewHolder.examePlace.setText("地点：" + getString(tmpBean.site));
		viewHolder.exameType.setText("形式：" + getString(tmpBean.examineFormat));
		viewHolder.placeNumber.setText("座位：" + getString(tmpBean.seatNumber));
		viewHolder.schoolPart.setText("校区：" + getString(tmpBean.campus));
		
		if (getCount() == 1){
			convertView.setBackgroundResource(R.drawable.full_selector);
		}else if (0 == position) {
			convertView.setBackgroundResource(R.drawable.top_selector);
		}else if (getCount()-1 == position) {
			convertView.setBackgroundResource(R.drawable.bottom_selector);
		}else {
			convertView.setBackgroundResource(R.drawable.middle_selector);
		}
		
		return convertView;
	}

	private String getString(String string){
		string = string.trim();
		if (string !=null && !string.equals("")){
			return string;
		}
		
		return "(没有数据)";
	}
	
	class ViewHolder{
		public TextView courseName;					//
		public TextView courseNumber;					//
		public TextView exameTime;				//
		public TextView examePlace;				//
		public TextView exameType;				//
		public TextView placeNumber;				//
		public TextView schoolPart;				//
	}
}
